home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / warlord.c < prev    next >
C/C++ Source or Header  |  1999-11-09  |  4KB  |  158 lines

  1. /***************************************************************************
  2. Warlords Driver by Lee Taylor and John Clegg
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. /***************************************************************************
  15.  
  16.   Convert the color PROM into a more useable format.
  17.  
  18.   The palette PROM are connected to the RGB output this way:
  19.  
  20.   bit 2 -- RED
  21.         -- GREEN
  22.   bit 0 -- BLUE
  23.  
  24. ***************************************************************************/
  25. void warlord_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  26. {
  27.     int i, j;
  28.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  29.  
  30.  
  31.     for (i = 0;i < Machine->drv->total_colors;i++)
  32.     {
  33.         int r,g,b;
  34.  
  35.         r = ((*color_prom >> 2) & 0x01) * 0xff;
  36.         g = ((*color_prom >> 1) & 0x01) * 0xff;
  37.         b = ((*color_prom >> 0) & 0x01) * 0xff;
  38.  
  39.         /* Colors 0x40-0x7f are converted to grey scale as it's used on the
  40.            upright version that had an overlay */
  41.         if (i >= Machine->drv->total_colors / 2)
  42.         {
  43.             int grey;
  44.  
  45.             /* Use the standard ratios: r = 30%, g = 59%, b = 11% */
  46.             grey = ((r != 0) * 0x4d) + ((g != 0) * 0x96) + ((b != 0) * 0x1c);
  47.  
  48.             r = g = b = grey;
  49.         }
  50.  
  51.         *(palette++) = r;
  52.         *(palette++) = g;
  53.         *(palette++) = b;
  54.  
  55.         color_prom++;
  56.     }
  57.  
  58.     for (i = 0; i < 8; i++)
  59.     {
  60.         for (j = 0; j < 4; j++)
  61.         {
  62.             COLOR(0,i*4+j) = i*16+j;
  63.             COLOR(1,i*4+j) = i*16+j*4;
  64.         }
  65.     }
  66. }
  67.  
  68.  
  69. /***************************************************************************
  70.  
  71.   Draw the game screen in the given osd_bitmap.
  72.   Do NOT call osd_update_display() from this function, it will be called by
  73.   the main emulation engine.
  74.  
  75. ***************************************************************************/
  76. void warlord_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  77. {
  78.     int offs, upright_mode, palette;
  79.  
  80.  
  81.     if (palette_recalc())
  82.         memset(dirtybuffer,1,videoram_size);
  83.  
  84.     /* Cocktail mode uses colors 0-3, upright 4-7 */
  85.  
  86.     upright_mode = input_port_0_r(0) & 0x80;
  87.     palette = ( upright_mode ? 4 : 0);
  88.  
  89.     for (offs = videoram_size - 1;offs >= 0;offs--)
  90.     {
  91.         if (dirtybuffer[offs])
  92.         {
  93.             int sx,sy,color,flipx,flipy;
  94.  
  95.             dirtybuffer[offs] = 0;
  96.  
  97.             sy = (offs / 32);
  98.             sx = (offs % 32);
  99.  
  100.             flipx = !(videoram [offs] & 0x40);
  101.             flipy =   videoram [offs] & 0x80;
  102.  
  103.             if (upright_mode)
  104.             {
  105.                 sx = 31 - sx;
  106.                 flipx = !flipx;
  107.             }
  108.  
  109.             /* The four quadrants have different colors */
  110.             color = ((sy & 0x10) >> 3) | ((sx & 0x10) >> 4) | palette;
  111.  
  112.             drawgfx(tmpbitmap,Machine->gfx[0],
  113.                     videoram [offs] & 0x3f,
  114.                     color,
  115.                     flipx, flipy,
  116.                     8*sx,8*sy,
  117.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  118.         }
  119.     }
  120.  
  121.  
  122.     /* copy the temporary bitmap to the screen */
  123.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  124.  
  125.  
  126.     /* Draw the sprites */
  127.     for (offs = 0;offs < 0x10;offs++)
  128.     {
  129.         int sx, sy, flipx, flipy, spritenum, color;
  130.  
  131.         sx = spriteram [offs + 0x20];
  132.         sy = 248 - spriteram[offs + 0x10];
  133.  
  134.         flipx = !(spriteram [offs] & 0x40);
  135.         flipy =   spriteram [offs] & 0x80;
  136.  
  137.         if (upright_mode)
  138.         {
  139.             sx = 248 - sx;
  140.             flipx = !flipx;
  141.         }
  142.  
  143.         spritenum = (spriteram[offs] & 0x3f);
  144.  
  145.         /* The four quadrants have different colors. This is not 100% accurate,
  146.            because right on the middle the sprite could actually have two or more
  147.            different color, but this is not noticable, as the color that
  148.            changes between the quadrants is mostly used on the paddle sprites */
  149.         color = ((sy & 0x80) >> 6) | ((sx & 0x80) >> 7) | palette;
  150.  
  151.         drawgfx(bitmap,Machine->gfx[1],
  152.                 spritenum, color,
  153.                 flipx, flipy,
  154.                 sx, sy,
  155.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  156.     }
  157. }
  158.